import { DialogWorkerMsgHandler } from '../components/dialog/DialogWorkerMsgHandler'
import StringUtils from '../utils/StringUtils'
import { JumpManager } from '../system/appJump/JumpManager'
import { DeviceUtils } from '../system/device/DeviceUtils'
import ApplicationManager from '../system/application/ApplicationManager'
import { TextInputWorkerMsgHandler } from '../components/textInput/TextInputWorkerMsgHandler'
import { TextAreaWorkerMsgHandler } from '../components/textArea/TextAreaWorkerMsgHandler'
import { WebViewWorkerMsgHandler } from '../components/webview/WebViewWorkerMsgHandler'
import Network from '../system/network/Network'
import { VideoPlayerWorkerMsgHandler } from '../components/videoplayer/VideoPlayerWorkerMsgHandler'
import ClipBoard from '../system/clipboard/ClipBoardManager'
import Accelerometer from '../system/sensor/AccelerometerUtils'
import DateTimeUtil from '../utils/DateTimeUtil'

import PreferencesUtils from '../utils/PreferencesUtils'
// worker线程中触发CPP调用JS
export class NapiHelper {
    static registerFunctions(registerFunc : Function) {
        NapiHelper.registerOthers(registerFunc);
        NapiHelper.registerJumpManager(registerFunc);
        NapiHelper.registerDeviceUtils(registerFunc);
        NapiHelper.registerTextInput(registerFunc);
        NapiHelper.registerTextArea(registerFunc);
        NapiHelper.registerWebView(registerFunc);
        NapiHelper.registerVideoPlay(registerFunc);
        NapiHelper.registerClipBoard(registerFunc);
        NapiHelper.registerSensor(registerFunc);
        NapiHelper.registerPreferences(registerFunc);
    }

    private static registerOthers(registerFunc : Function) {
        registerFunc('DiaLog.showDialog', DialogWorkerMsgHandler.showDialog);
        registerFunc('DiaLog.showTextInputDialog', DialogWorkerMsgHandler.showTextInputDialog);
        registerFunc('DiaLog.hideTextInputDialog', DialogWorkerMsgHandler.hideTextInputDialog);
        registerFunc('StringUtils.getWidth', StringUtils.getWidth);
        registerFunc('ApplicationManager.exit', ApplicationManager.exit);
        registerFunc('ApplicationManager.getAppVersionCode', ApplicationManager.getAppVersionCode);
        registerFunc('ApplicationManager.getAppName', ApplicationManager.getAppName);
        registerFunc('ApplicationManager.getAAID', ApplicationManager.getAAID);
        registerFunc('ApplicationManager.getBundleName', ApplicationManager.getBundleName);
        registerFunc('ApplicationManager.declarePermission', ApplicationManager.declarePermission);
        registerFunc('ApplicationManager.getSandboxPath', ApplicationManager.getSandboxPath);
        registerFunc('Network.isWifiConnected', Network.isWifiConnected);
        registerFunc('Network.getNetWorkType', Network.getNetWorkType);
        registerFunc('DataTime.getActiveTimeStamp', DateTimeUtil.getActiveTimeStamp);
        registerFunc('DataTime.getTimeStamp', DateTimeUtil.getTimeStamp);
    }

    private static registerJumpManager(registerFunc : Function) {
        registerFunc('JumpManager.openApp', JumpManager.openApp);
        registerFunc('JumpManager.openAppInAppMarket', JumpManager.openAppInAppMarket);
        registerFunc('JumpManager.openUrl', JumpManager.openUrl);
        registerFunc('JumpManager.openImagePicker', JumpManager.openImagePicker);
    }

    private static registerDeviceUtils(registerFunc : Function) {
        registerFunc('DeviceUtils.getDpi', DeviceUtils.getDpi);
        registerFunc('DeviceUtils.getName', DeviceUtils.getName);
        registerFunc('DeviceUtils.getModel', DeviceUtils.getModel);
        registerFunc('DeviceUtils.getSdkApiVersion', DeviceUtils.getSdkApiVersion);
        registerFunc('DeviceUtils.getDisplayOrientation', DeviceUtils.getDisplayOrientation);
        registerFunc('DeviceUtils.getBatterySOC', DeviceUtils.getBatterySOC);
        registerFunc('DeviceUtils.getSystemLanguage', DeviceUtils.getSystemLanguage);
        registerFunc('DeviceUtils.setWindowPrivacyMode', DeviceUtils.setWindowPrivacyMode);
        registerFunc('DeviceUtils.startVibration', DeviceUtils.startVibration);
        registerFunc('DeviceUtils.setKeepScreenOn', DeviceUtils.setKeepScreenOn);
        registerFunc('DeviceUtils.getTop', DeviceUtils.getTop);
        registerFunc('DeviceUtils.getBottom', DeviceUtils.getBottom);
        registerFunc('DeviceUtils.getLeft', DeviceUtils.getLeft);
        registerFunc('DeviceUtils.getRight', DeviceUtils.getRight);
    }

    private static registerTextInput(registerFunc : Function) {
        registerFunc('TextInput.createTextInput', TextInputWorkerMsgHandler.createTextInput);
        registerFunc('TextInput.removeTextInput', TextInputWorkerMsgHandler.removeTextInput);
        registerFunc('TextInput.setCurrentText', TextInputWorkerMsgHandler.setCurrentText);
        registerFunc('TextInput.setTextInputViewRect', TextInputWorkerMsgHandler.setTextInputViewRect);
        registerFunc('TextInput.setTextInputVisible', TextInputWorkerMsgHandler.setTextInputVisible);
        registerFunc('TextInput.setTextInputBold', TextInputWorkerMsgHandler.setTextInputBold);
        registerFunc('TextInput.setTextInputEditable', TextInputWorkerMsgHandler.setTextInputEditable);
        registerFunc('TextInput.setTextInputPlaceHolder', TextInputWorkerMsgHandler.setTextInputPlaceHolder);
        registerFunc('TextInput.setTextInputFontSize', TextInputWorkerMsgHandler.setTextInputFontSize);
        registerFunc('TextInput.setTextInputFontColor', TextInputWorkerMsgHandler.setTextInputFontColor);
        registerFunc('TextInput.setTextInputFontPath', TextInputWorkerMsgHandler.setTextInputFontPath);
        registerFunc('TextInput.setTextInputPlaceHolderFontSize', TextInputWorkerMsgHandler.setTextInputPlaceHolderFontSize);
        registerFunc('TextInput.setTextInputPlaceHolderFontColor', TextInputWorkerMsgHandler.setTextInputPlaceHolderFontColor);
        registerFunc('TextInput.setTextInputPlaceHolderFontPath', TextInputWorkerMsgHandler.setTextInputPlaceHolderFontPath);
        registerFunc('TextInput.setTextInputMaxLength', TextInputWorkerMsgHandler.setTextInputMaxLength);
        registerFunc('TextInput.setTextInputAlign', TextInputWorkerMsgHandler.setTextInputAlign);
        registerFunc('TextInput.setNativeInputMode', TextInputWorkerMsgHandler.setNativeInputMode);
        registerFunc('TextInput.setNativeInputFlag', TextInputWorkerMsgHandler.setNativeInputFlag);
        registerFunc('TextInput.setNativeReturnKey', TextInputWorkerMsgHandler.setNativeReturnKey);
        registerFunc('TextInput.hideAllTextInput', TextInputWorkerMsgHandler.hideAllTextInput);
    }

    private static registerTextArea(registerFunc : Function) {
        registerFunc('TextArea.createTextArea', TextAreaWorkerMsgHandler.createTextArea);
        registerFunc('TextArea.removeTextArea', TextAreaWorkerMsgHandler.removeTextArea);
        registerFunc('TextArea.setCurrentText', TextAreaWorkerMsgHandler.setCurrentText);
        registerFunc('TextArea.setTextAreaViewRect', TextAreaWorkerMsgHandler.setTextAreaViewRect);
        registerFunc('TextArea.setTextAreaVisible', TextAreaWorkerMsgHandler.setTextAreaVisible);
        registerFunc('TextArea.setTextAreaBold', TextAreaWorkerMsgHandler.setTextAreaBold);
        registerFunc('TextArea.setTextAreaEditable', TextAreaWorkerMsgHandler.setTextAreaEditable);
        registerFunc('TextArea.setTextAreaPlaceHolder', TextAreaWorkerMsgHandler.setTextAreaPlaceHolder);
        registerFunc('TextArea.setTextAreaFontSize', TextAreaWorkerMsgHandler.setTextAreaFontSize);
        registerFunc('TextArea.setTextAreaFontColor', TextAreaWorkerMsgHandler.setTextAreaFontColor);
        registerFunc('TextArea.setTextAreaFontPath', TextAreaWorkerMsgHandler.setTextAreaFontPath);
        registerFunc('TextArea.setTextAreaPlaceHolderFontSize', TextAreaWorkerMsgHandler.setTextAreaPlaceHolderFontSize);
        registerFunc('TextArea.setTextAreaPlaceHolderFontColor', TextAreaWorkerMsgHandler.setTextAreaPlaceHolderFontColor);
        registerFunc('TextArea.setTextAreaPlaceHolderFontPath', TextAreaWorkerMsgHandler.setTextAreaPlaceHolderFontPath);
        registerFunc('TextArea.setTextAreaMaxLength', TextAreaWorkerMsgHandler.setTextAreaMaxLength);
        registerFunc('TextArea.setTextAreaAlign', TextAreaWorkerMsgHandler.setTextAreaAlign);
        registerFunc('TextArea.setNativeInputMode', TextAreaWorkerMsgHandler.setNativeInputMode);
        registerFunc('TextArea.setNativeInputFlag', TextAreaWorkerMsgHandler.setNativeInputFlag);
        registerFunc('TextArea.setNativeReturnKey', TextAreaWorkerMsgHandler.setNativeReturnKey);
        registerFunc('TextArea.hideAllTextArea', TextAreaWorkerMsgHandler.hideAllTextArea);
    }

    private static registerWebView(registerFunc : Function) {
        registerFunc('WebView.createWebView', WebViewWorkerMsgHandler.createWebView);

        registerFunc('WebView.removeWebView', WebViewWorkerMsgHandler.removeWebView);
        registerFunc('WebView.loadData', WebViewWorkerMsgHandler.loadData);

        registerFunc('WebView.loadURL', WebViewWorkerMsgHandler.loadURL);
        registerFunc('WebView.loadFile', WebViewWorkerMsgHandler.loadFile);
        registerFunc('WebView.stopLoading', WebViewWorkerMsgHandler.stopLoading);
        registerFunc('WebView.reload', WebViewWorkerMsgHandler.reload);


        registerFunc('WebView.canGoBack', WebViewWorkerMsgHandler.canGoBack);
        registerFunc('WebView.canGoForward', WebViewWorkerMsgHandler.canGoForward);

        registerFunc('WebView.goBack', WebViewWorkerMsgHandler.goBack);
        registerFunc('WebView.goForward', WebViewWorkerMsgHandler.goForward);

        registerFunc('WebView.setWebViewRect', WebViewWorkerMsgHandler.setWebViewRect);
        registerFunc('WebView.setVisible', WebViewWorkerMsgHandler.setVisible);
        registerFunc('WebView.setOpacityWebView', WebViewWorkerMsgHandler.setOpacityWebView);
        registerFunc('WebView.setBackgroundTransparent', WebViewWorkerMsgHandler.setBackgroundTransparent);
        registerFunc('WebView.evaluateJS', WebViewWorkerMsgHandler.evaluateJS);
        registerFunc('WebView.setScalesPageToFit', WebViewWorkerMsgHandler.setScalesPageToFit);

        registerFunc('WebView.deleteCookie', WebViewWorkerMsgHandler.deleteCookie);
    }

    private static registerVideoPlay(registerFunc : Function) {
        registerFunc('VideoPlayer.createVideoPlayer', VideoPlayerWorkerMsgHandler.createVideoPlayer);
        registerFunc('VideoPlayer.removeVideoPlayer', VideoPlayerWorkerMsgHandler.removeVideoPlayer);
        registerFunc('VideoPlayer.setURL', VideoPlayerWorkerMsgHandler.setURL);
        registerFunc('VideoPlayer.setLooping', VideoPlayerWorkerMsgHandler.setLooping);
        registerFunc('VideoPlayer.setVideoPlayerRect', VideoPlayerWorkerMsgHandler.setVideoPlayerRect);
        registerFunc('VideoPlayer.play', VideoPlayerWorkerMsgHandler.play);
        registerFunc('VideoPlayer.pause', VideoPlayerWorkerMsgHandler.pause);
        registerFunc('VideoPlayer.stop', VideoPlayerWorkerMsgHandler.stop);
        registerFunc('VideoPlayer.setVisible', VideoPlayerWorkerMsgHandler.setVisible);
        registerFunc('VideoPlayer.requestFullscreen', VideoPlayerWorkerMsgHandler.requestFullscreen);
        registerFunc('VideoPlayer.seekTo', VideoPlayerWorkerMsgHandler.seekTo);
        registerFunc('VideoPlayer.setKeepAspectRatioEnabled', VideoPlayerWorkerMsgHandler.setKeepAspectRatioEnabled);
    }

    private static registerClipBoard(registerFunc : Function) {
        registerFunc('ClipBoard.setClipBoardText', ClipBoard.setClipBoardText);
        registerFunc('ClipBoard.getClipBoardText', ClipBoard.getClipBoardText);
    }

    private static registerSensor(registerFunc : Function) {
        registerFunc('Accelerometer.enable', Accelerometer.enable);
        registerFunc('Accelerometer.disable', Accelerometer.disable);
    }

    private static registerPreferences(registerFunc:Function){
        registerFunc('PreferencesUtils.get', PreferencesUtils.get);
        registerFunc('PreferencesUtils.put', PreferencesUtils.put);
        registerFunc('PreferencesUtils.delete', PreferencesUtils.delete);
    }
}